<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>
        <ui:composition template="../templates/default3.xhtml">
            <ui:define name="content">
                <h:form binding="#{creditManagerBean.loadReceipts}">
                    <p:panel header="Customer Details" id="customerDetailsPanel">
                        <table width="100%" border="0">
                            <tr>
                                <td width="200px">
                                    Company:
                                </td>
                                <td>
                                    <h:outputText id="company" value="#{creditManagerBean.selectedCustomer.company}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Description:
                                </td>
                                <td>
                                    <h:outputText id="description" value="#{creditManagerBean.selectedCustomer.description}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Annual Revenue:
                                </td>
                                <td>
                                    <h:outputText id="revenue" value="#{creditManagerBean.selectedCustomer.revenue}">
                                        <f:convertNumber type="currency"/>
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Number of Employees:
                                </td>
                                <td>
                                    <h:outputText id="numEmployee" value="#{creditManagerBean.selectedCustomer.numEmployee}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Contact Person
                                </td>
                                <td>
                                    <h:outputText id="contactPerson" value="#{creditManagerBean.selectedCustomer.firstName}, 
                                                  #{creditManagerBean.selectedCustomer.lastName}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Designation:
                                </td>
                                <td>
                                    <h:outputText id="title" value="#{creditManagerBean.selectedCustomer.title}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Contact Number:
                                </td>
                                <td>
                                    <h:outputText id="phone" value="#{creditManagerBean.selectedCustomer.phone}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Credit Rank:
                                </td>
                                <td>
                                    <h:outputText id="rank" value="#{creditManagerBean.selectedCustomer.credit.creditRank}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Credit Limit:
                                </td>
                                <td>
                                    <h:outputText id="limit" value="#{creditManagerBean.selectedCustomer.credit.creditLimit}">
                                        <f:convertNumber type="currency"/>
                                    </h:outputText>
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                    <p:panel header="Receipts" id="receiptsPanel">
                        <p:messages />
                        
                        <p:dataTable id="receipts" var="receipt" value="#{creditManagerBean.receipts}" 
                                     emptyMessage="No receipts found with given criteria."
                                     selection="#{creditManagerBean.selectedReceipt}"
                                     selectionMode="single"
                                     rowSelectListener="#{creditManagerBean.receiptsRowSelectListener}"
                                     onRowSelectUpdate="paymentDetailsPanel" 
                                     onRowUnselectUpdate="paymentDetailsPanel">
                            <p:column headerText="Receipt ID" sortBy="#{receipt.id}">  
                                <h:outputText value="#{receipt.id}">
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Receipt Date" 
                                      sortBy="#{receipt.paymentDate}">  
                                <h:outputText value="#{receipt.paymentDate}"> 
                                    <f:convertDateTime pattern="dd-MM-yyyy hh:mm a" timeZone="#{defaultManagerBean.tz}"/>
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Receipt Amount" sortBy="#{receipt.amountPaid}">  
                                <h:outputText value="#{receipt.amountPaid}">  
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="Status" sortBy="#{receipt.status}">  
                                <h:outputText value="#{receipt.status}">
                                </h:outputText>
                            </p:column> 
                        </p:dataTable>
                    </p:panel>
                    <p:panel header="Payment Details" id="paymentDetailsPanel">
                        <table>
                            <tr>
                                <td width="200px">Invoice ID:</td>
                                <td>
                                    <h:outputText id="invoiceId" 
                                                  value="#{creditManagerBean.selectedReceipt.payment.invoice.id}" 
                                                  title="ID of invoice.">
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">Payment Date:</td>
                                <td>
                                    <h:outputText id="paymentDate" 
                                                  value="#{creditManagerBean.selectedReceipt.payment.paymentDate}" 
                                                  title="Date of payment.">
                                        <f:convertDateTime pattern="dd-MM-yyyy hh:mm a" timeZone="#{defaultManagerBean.tz}"/>
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">Payment Amount:</td>
                                <td>
                                    <h:outputText id="paymentAmount" 
                                                  value="#{creditManagerBean.selectedReceipt.payment.amountPaid}" 
                                                  title="Amount paid.">
                                        <f:convertNumber type="currency"/>
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">Balance Used:</td>
                                <td>
                                    <h:outputText id="balanceUsed" 
                                                  value="#{creditManagerBean.selectedReceipt.payment.balanceUsed}" 
                                                  title="Balance used.">
                                        <f:convertNumber type="currency"/>
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">Payment Status:</td>
                                <td>
                                    <h:outputText id="paymentStatus" 
                                                  value="#{creditManagerBean.selectedReceipt.payment.status}" 
                                                  title="Payment status.">
                                    </h:outputText>
                                </td>
                            </tr>
                        </table>
                       
                    </p:panel>
                    <table class="table-submit">
                        <tr>
                            <td align="center">
                                <p:commandButton id="btnBackFromReceipts" value="Back" 
                                     title="Go back to previous page."
                                     actionListener="#{creditManagerBean.back}"
                                     ajax="true"/>&nbsp;&nbsp;&nbsp;
                    <p:commandButton id="btnGoToViewPayment" value="View Payment Details" 
                                     title="View payment details."
                                     actionListener="#{creditManagerBean.go}"
                                     update="receiptsPanel"
                                     ajax="true"/>
                       <font size="1">&nbsp;&nbsp;&nbsp;
                            <h:commandLink id="Receipt" actionListener="#{reportManagerBean.getReports}"
                                           title="View Receipt.">
                                <h:outputText value="+ Receipt"/>
                            </h:commandLink>
                        </font>
                            </td>
                        </tr>
                    </table>
                    
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>
